import os
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from tkinter.scrolledtext import ScrolledText
import daiMa

# 主窗口设置
root = ttk.Window(
    title="微信自动发消息",
    themename="vapor"
)

# 执行批量发送指令
FS_button = ttk.Button(root, text="开始发送", command=daiMa.main1, bootstyle=(INFO, OUTLINE))

# 将一件发送放置在主窗口内
FS_button.pack(side=LEFT, padx=50, pady=10)


# 编辑发送客户信息
def open_file():
    os.startfile('客户信息.txt')


# 设置相关绑定参数
FS_button = ttk.Button(root, text="发送客户修改", command=open_file, bootstyle=(INFO, OUTLINE))

# 将按钮放置在主窗口内
FS_button.pack(side=LEFT, padx=5)


# 发送内容修改
def open_file():
    os.startfile('发送内容.txt')


# 添加按钮，以及按钮的文本，并通过command 参数设置关闭窗口的功能
FS_button = ttk.Button(root, text="发送内容修改", command=open_file, bootstyle=(INFO, OUTLINE))
# 将按钮放置在主窗口内
FS_button.pack(side=LEFT)

# 在当前界面查看文件信息
style = ttk.Style()
# 设置滚动窗
textbox = ScrolledText(
    master=root,
    highlightcolor=style.colors.primary,
    highlightbackground=style.colors.border,
    highlightthickness=1
)
# 设置滚动窗为填满当前界面
textbox.pack(fill=BOTH)

# 滚动窗默认显示文字
default_txt = "单击浏览按钮以打开新的文本文件。"
textbox.insert(END, default_txt)

filename = ttk.StringVar()
file_entry = ttk.Entry(root, textvariable=filename)
file_entry.pack(side=LEFT, fill=X, expand=YES, padx=(0, 5), pady=10)


def open_file1():
    with open('客户信息.txt', encoding='utf-8') as f:
        textbox.delete('1.0', END)
        textbox.insert(END, f.read())
        filename.set(str(f))


def open_file2():
    with open('发送内容.txt', encoding='utf-8') as f:
        textbox.delete('1.0', END)
        textbox.insert(END, f.read())
        filename.set(str(f))


browse_btn = ttk.Button(root, text="查看准备发送的客户", command=open_file1)
browse_btn1 = ttk.Button(root, text="查看准备发送的内容", command=open_file2)
browse_btn.pack(side=RIGHT, fill=X, padx=(5, 0), pady=10)
browse_btn1.pack(side=RIGHT, fill=X, padx=(5, 0), pady=10)

root.mainloop()
